Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

2K
Views
Docker-Compose postgres upgrade initdb: error: el directorio "/var/lib/postgresql/data" existe pero no está vacío

Instalé postgres 11 usando docker-compose. Quería actualizarlo a 12, pero aunque eliminé el contenedor y su volumen, el estado del contenedor dice "Reiniciando".

Aquí está mi archivo docker-compose

 version: '3.5' services: postgres: image: postgres:12 environment: POSTGRES_HOST_AUTH_METHOD: "trust" ports: - "5432" restart: always volumes: - /etc/postgresql/12/postgresql.conf:/var/lib/postgresql/data/postgresql.conf - db_data:/var/lib/postgresql/data volumes: db_data:

Sin embargo, no funciona y los registros tienen el siguiente problema

 2020-07-02T12:54:47.012973448Z The files belonging to this database system will be owned by user "postgres". 2020-07-02T12:54:47.013030445Z This user must also own the server process. 2020-07-02T12:54:47.013068962Z 2020-07-02T12:54:47.013222608Z The database cluster will be initialized with locale "en_US.utf8". 2020-07-02T12:54:47.013261425Z The default database encoding has accordingly been set to "UTF8". 2020-07-02T12:54:47.013281815Z The default text search configuration will be set to "english". 2020-07-02T12:54:47.013293326Z 2020-07-02T12:54:47.013303793Z Data page checksums are disabled. 2020-07-02T12:54:47.013313919Z 2020-07-02T12:54:47.013450079Z initdb: error: directory "/var/lib/postgresql/data" exists but is not empty 2020-07-02T12:54:47.013487706Z If you want to create a new database system, either remove or empty 2020-07-02T12:54:47.013501126Z the directory "/var/lib/postgresql/data" or run initdb 2020-07-02T12:54:47.013512379Z with an argument other than "/var/lib/postgresql/data".

¿Cómo podría eliminar o vaciar este /var/lib/postgresql/data cuando el contenedor se reinicia constantemente?

Gracias por adelantado

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Citando a @yosifkit de este número

El volumen debe estar vacío o una base de datos postgres ya inicializada válida con el archivo PG_VERSION allí para que se pueda omitir el inicio.

... Si hay archivos o carpetas allí como lost+found , es probable que no se inicialicen. Si hay archivos que desea mantener en el volumen (o sobre los que no tiene control), puede ajustar la variable de entorno PGDATA para que apunte a un subdirectorio allí como -e PGDATA=/var/lib/postgresql/data/db-files/ .

Así que agregué PGDATA a la sección de environment del archivo de composición para resolver el problema (observe el some_name al final):

 services: postgres: image: postgres:12 environment: PGDATA: /var/lib/postgresql/data/some_name/
over 4 years ago · Santiago Trujillo Report

0

Tengo este problema porque /var/lib/postgresql/data/postgresql.conf y /var/lib/postgresql/data se superponen en el contenedor acoplable en /var/lib/postgresql/ .

Un ejemplo de una configuración rota es:

 version: "3.8" services: db: image: "postgres:10" ports: - "5432:5432" volumes: - ./postgresql.conf:/var/lib/postgresql/data/postgresql.conf - ./pg-data:/var/lib/postgresql/data

Para evitar esto, le digo a PostgreSQL que busque su configuración en /etc/postgresql.conf para que los volúmenes superpuestos no ocurran así:

 version: "3.8" services: db: image: "postgres:10" command: ["postgres", "-c", "config_file=/etc/postgresql.conf"] ports: - "5432:5432" volumes: - ./postgresql.conf:/etc/postgresql.conf - ./pg-data:/var/lib/postgresql/data

Esto es similar a lo que sugiere pmsoltani , pero muevo la ubicación del archivo postgresql.conf en lugar del directorio de datos.

over 4 years ago · Santiago Trujillo Report

0

Tuve el mismo problema hoy, lo solucioné eliminando el contenido del volumen db_data en su caso

 docker volume ls docker volume inspect db_data <-- will show you the mountpoint

Fui al directorio (punto de montaje) ej: /ruta/datos

 cp data data.backup cd data rm -R *

E iniciar servicios:

 docker-compose up -d
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!